package generator;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Random;

import core.course.Course;

/**
 * Creates instances of the scheduling problem.
 * 
 * @author omerlevy
 */
public class ProblemGeneratorMain {

	/**
	 * Runs the course bank generator and writes the results to a file.
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		if (args.length != 1) {
			System.out.println("Legal params: <output-dir>");
			System.exit(1);
		}
		
		BufferedWriter output = new BufferedWriter(new FileWriter(
				args[0] + '/' + System.currentTimeMillis() + ".csv"));
		
		CourseBank bank = new CourseBankGenerator().generateCourseBank(
				new Random(), NUM_COURSES);
		
		output.append("Course");
		output.append(DELIMITER);
		output.append("Time");
		output.append(DELIMITER);
		output.append("Workload");
		output.append(DELIMITER);
		output.append("Grade");
		output.append(DELIMITER);
		output.append("Adjacents");
		output.append("\n");
		
		for (int i = 0; i < NUM_COURSES; i++) {
			Course course = bank.getCourse(i);
			
			output.append(Integer.toString(course.getId()));
			output.append(DELIMITER);
			output.append(Integer.toString(course.getTime()));
			output.append(DELIMITER);
			output.append(Integer.toString(course.getWorkload()));
			output.append(DELIMITER);
			output.append(Integer.toString(course.getGrade()));
			output.append(DELIMITER);
			for (int adjacent : course.getAdjacents()) {				
				output.append(Integer.toString(adjacent));
				output.append(DELIMITER);
			}
			output.append("\n");
		}
	
		output.flush();
		output.close();
	}

	/** The number of available courses. */
	public static final int NUM_COURSES = 100;

	/** The delimiter in the output file. */
	public static final char DELIMITER = ',';
	
}
